import pandas as pd
import numpy as np
df = pd.read_csv('data/pokemon.csv')

(df[['HP', 'Attack', 'Defense', 'Sp. Atk', 'Sp. Def', 'Speed'
   ]].sum(1)!=df['Total']).mean()

dp_dup = df.drop_duplicates('#', keep='first')
dp_dup['Type 1'].nunique()

'''
根据不同的值区分不同的标签
'''
df['Attack'].mask(df['Attack']>120, 'high'
                 ).mask(df['Attack']<50, 'low').mask((50<=df['Attack']
                 )&(df['Attack']<=120), 'mid').head()
np.random.seed(0)
s = pd.Series(np.random.randint(-1,2,30).cumsum())
def ewm_func(x, alpha=0.2):
    win = (1-alpha)**np.arange(x.shape[0])[::-1]
    res = (win*x).sum()/win.sum()
    return res
s.expanding().apply(ewm_func).head()
s.rolling(window=4).apply(ewm_func).head() # 无需对原函数改动